home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / et / et3_0-a1.lha / et3 / src / VObject.h < prev    next >
C/C++ Source or Header  |  1992-07-17  |  7KB  |  253 lines

  1. #ifndef VObject_First
  2. #ifdef __GNUG__
  3. //pragma once
  4. #pragma interface
  5. #endif
  6. #define VObject_First
  7.  
  8. #include "Types.h"
  9. #include "Port.h"
  10. #include "EvtHandler.h"
  11. #include "Command.h"
  12. #include "CmdNo.h"
  13.  
  14. class Clipper;
  15. class View;
  16. class Window;
  17. class Collection;
  18.  
  19. enum VObjFlags {
  20.     eVObjEnabled    =   BIT(eEvtLast+1),
  21.     eVObjOpen       =   BIT(eEvtLast+2),
  22.     eVObjHFixed     =   BIT(eEvtLast+3),
  23.     eVObjVFixed     =   BIT(eEvtLast+4),
  24.     eVObjLayoutCntl =   BIT(eEvtLast+5),
  25.     eVObjKbdFocus   =   BIT(eEvtLast+6),
  26.     eVObjShowPage   =   BIT(eEvtLast+7),
  27.     eVObjHighlight  =   BIT(eEvtLast+8),
  28.     eVObjDefault    =   eVObjEnabled,
  29.     eVObjLast       =   eEvtLast + 8
  30. };
  31.  
  32. enum VObjAlign {
  33.     eVObjHLeft      = BIT(0),
  34.     eVObjHCenter    = BIT(1),
  35.     eVObjHRight     = BIT(2),
  36.     eVObjHExpand    = BIT(3),
  37.     eVObjHEqual     = BIT(4),
  38.     eVObjHGapExpand = BIT(5),
  39.     eVObjH          = eVObjHLeft|eVObjHCenter|eVObjHRight, 
  40.     eVObjVTop       = BIT(8),
  41.     eVObjVBase      = BIT(9),
  42.     eVObjVCenter    = BIT(10),
  43.     eVObjVBottom    = BIT(11), 
  44.     eVObjVExpand    = BIT(12),
  45.     eVObjVEqual     = BIT(13),
  46.     eVObjVGapExpand = BIT(14),
  47.     eVObjV          = eVObjVTop|eVObjVBase|eVObjVCenter|eVObjVBottom 
  48. };
  49.  
  50. extern const int cAutoSize;
  51. extern Point gBorder;
  52.  
  53. //---- VObject -----------------------------------------------------------------
  54.  
  55. class VObject : public EvtHandler {
  56.     VObject *container;
  57.  
  58. public:
  59.     Rectangle contentRect;
  60.  
  61. public:
  62.     MetaDef(VObject);
  63.  
  64.     VObject(Rectangle r, int id= cIdNone);
  65.     VObject(int id= cIdNone);
  66.     ~VObject();
  67.  
  68.     void FreeAll();
  69.  
  70.     Point GetPortPoint(Point p);
  71.     virtual Rectangle GetViewedRect();
  72.  
  73.     virtual int Size();
  74.     virtual Iterator *MakeIterator(bool forward= TRUE);
  75.     virtual VObject *SetAt(int at, VObject *vop);
  76.     virtual VObject *At(int n);
  77.     virtual void Add(VObject*);
  78.     virtual VObject *Remove(VObject*);
  79.     virtual void RemoveFromContainer();
  80.     void SendDown(int, int, void*);
  81.  
  82.     //---- acessing ----------------------------
  83.     bool Enabled()
  84.     { return TestFlag(eVObjEnabled); }
  85.     virtual void Enable(bool b= TRUE, bool redraw= TRUE);
  86.     void Disable(bool redraw= TRUE)
  87.     { Enable(FALSE, redraw); }
  88.     virtual bool IsOpen();
  89.  
  90.     //---- sizes -------------------------------
  91.     virtual Metric GetMinSize();
  92.     int Width()
  93.     { return contentRect.extent.x; }
  94.     int Height()
  95.     { return contentRect.extent.y; }
  96.     int Base();
  97.     Point GetExtent()
  98.     { return contentRect.extent; }
  99.     Point GetOrigin()
  100.     { return contentRect.origin; };
  101.     Rectangle ContentRect()
  102.     { return contentRect; }
  103.  
  104.     void SetContentRect(Rectangle, bool);
  105.     virtual void SetExtent(Point);
  106.     virtual void ExtentChanged(VObject *what);
  107.     virtual void SetOrigin(Point);
  108.     void SetWidth(int w)
  109.     { SetExtent(Point(w,Height())); }
  110.     void SetHeight(int h)
  111.     { SetExtent(Point(Width(),h)); }
  112.     void Move(Point delta, bool redraw= TRUE);
  113.  
  114.     void CalcExtent();
  115.     virtual void Open(bool mode= TRUE);
  116.     void Close()
  117.     { Open(FALSE); }
  118.  
  119.     void Align(Point at, Metric m, VObjAlign a);
  120.     virtual bool ContainsPoint(Point p);
  121.  
  122.     //---- drawing ----------------------------
  123.     virtual void Focus();
  124.     virtual void DrawAll(Rectangle, bool highlight= FALSE);
  125.     virtual void DrawInner(Rectangle r, bool highlight= FALSE);
  126.     virtual void DrawHighlight(Rectangle);
  127.     virtual void Draw(Rectangle);
  128.     virtual void Outline2(Point, Point);
  129.     void Outline(Point delta);
  130.     // alternative interface to Outline2
  131.     void OutlineRect(Rectangle r);
  132.     // alternative interface to Outline2
  133.     virtual void Highlight(HighlightState);
  134.     virtual void InvalidateRect(Rectangle r);
  135.     virtual void InvalidateViewRect(Rectangle r);
  136.     void ForceRedraw();
  137.     void UpdateEvent();
  138.     virtual GrCursor GetCursor(Point p);
  139.     void Print();
  140.     virtual void Scroll(int mode, Point scroll, bool redraw= TRUE);
  141.     virtual void RevealRect(Rectangle, Point);
  142.     virtual void RevealAlign(Rectangle r, VObjAlign al= VObjAlign(eVObjHLeft+eVObjVTop));
  143.     void Reveal()
  144.     { RevealRect(contentRect, contentRect.extent); }
  145.  
  146.     Command *Input(Point lp, Token &t, Clipper *cl);
  147.     virtual Command *DispatchEvents(Point lp, Token &t, Clipper *cl);
  148.     virtual void DoTrackMouse(TrackPhase, Point);
  149.  
  150.     virtual VObject *Detect(BoolFun f, void *arg);
  151.     // find first entry where f returns true
  152.     VObject *FindItem(int);
  153.     VObject *FindItem(Point);
  154.     VObject *FindItem(VObject*);
  155.     VObject *FindItemPtr(VObject *g);
  156.  
  157.     //---- container handling ------------------
  158.     virtual void SetContainer(VObject*);
  159.     virtual void ClearContainer(VObject*);
  160.     VObject *GetContainer()
  161.     { return container; }
  162.     
  163.     VObject *FindContainerOfClass(Class *cla);
  164.     View *GetView();
  165.     Clipper *Getclipper();
  166.     Window *GetWindow();
  167.     virtual Point ContainerPoint(Point);
  168.     virtual void ReadEvent(Token &t, int timeout= -1, bool overread= TRUE);
  169.  
  170.     //---- keyboard focus
  171.     bool WantsKbdFocus()
  172.     { return TestFlag(eVObjKbdFocus); }
  173.     
  174.     virtual Command *GetMover();
  175.     virtual Command *GetStretcher();
  176.     
  177.     EvtHandler *GetNextHandler();
  178.     virtual Command *DoRightButtonDownCommand(Point, Token, int, Clipper*);
  179.     virtual Command *DoLeftButtonDownCommand(Point, Token, int);
  180.     virtual Command *DoMiddleButtonDownCommand(Point, Token, int);
  181.     
  182.     virtual Command *DoKeyCommand(int, Token);
  183.     virtual Command *DoCursorKeyCommand(EvtCursorDir, Token);
  184.     virtual Command *DoFunctionKeyCommand(int, Token);
  185.     
  186.     virtual Command *DoOtherEventCommand(Point, Token);
  187.     virtual Command *TrackInContent(Point, Token, Command*);
  188.  
  189.     //---- generic methods --------------------
  190.     OStream& PrintOn(OStream&);
  191.     IStream& ReadFrom(IStream&);
  192.     void CollectParts(Collection*);
  193. };
  194.  
  195. //---- VObjectCommand ----------------------------------------------------------
  196.  
  197. class VObjectCommand: public Command {
  198. protected:
  199.     VObject *vop;
  200.     Rectangle oldRect, lastRect, constrainRect, newRect;
  201.     Point delta, grid;
  202.     GrCursor newcursor, oldcursor;
  203.     bool firstmove;
  204.     int hysterese;
  205.  
  206. protected:
  207.     VObjectCommand(VObject *g);
  208.     void Init(VObject *g, Rectangle cr, Point gr, GrCursor cd, int hy);
  209.     Command *TrackMouse(TrackPhase, Point, Point, Point);
  210.     void TrackConstrain(Point, Point, Point*);    
  211.     void TrackFeedback(Point, Point, bool);
  212.     void DoIt();
  213.     void UndoIt();
  214. };
  215.  
  216. //---- VObjectMover ------------------------------------------------------------
  217.  
  218. class VObjectMover: public VObjectCommand {
  219. protected:
  220.     Point origin;
  221.  
  222.     void Init(VObject *g, Rectangle cr, Point gr, GrCursor, int hy);
  223.  
  224. public:
  225.     VObjectMover(VObject*);
  226.     VObjectMover(VObject*, Rectangle);
  227.     VObjectMover(VObject*, Rectangle, Point, GrCursor cr= eCrsMoveHand, int hy= 2);
  228.  
  229.     Command *TrackMouse(TrackPhase, Point, Point, Point);
  230. };
  231.  
  232. //---- VObjectStretcher --------------------------------------------------------
  233.  
  234. class VObjectStretcher: public VObjectCommand {
  235. protected:
  236.     Point minSize, p1, p2;
  237.     int corner;
  238.  
  239.     void Init(VObject *g, Rectangle cr, Point gr, GrCursor, int hy, Point ms);
  240.  
  241. public:
  242.     VObjectStretcher(VObject*);
  243.     VObjectStretcher(VObject*, Rectangle);
  244.     VObjectStretcher(VObject*, Rectangle, Point ms);
  245.     VObjectStretcher(VObject*, Rectangle, Point ms, Point,
  246.                       GrCursor cr= eCrsMoveStretch, int hy= 2);
  247.  
  248.     Command *TrackMouse(TrackPhase, Point, Point, Point);
  249.     void TrackConstrain(Point, Point, Point*);
  250. };
  251.  
  252. #endif
  253.